package com.example.common.room

import androidx.room.*
import kotlinx.coroutines.flow.Flow

/**
 * 评论草稿数据访问对象
 */
@Dao
interface CommentDraftDao {
    
    /**
     * 获取指定视频的评论草稿
     */
    @Query("SELECT * FROM comment_draft WHERE videoId = :videoId")
    fun getDraftByVideoId(videoId: Int): CommentDraft?
    
    /**
     * 获取所有评论草稿
     */
    @Query("SELECT * FROM comment_draft ORDER BY saveTime DESC")
    fun getAllDrafts(): Flow<List<CommentDraft>>
    
    /**
     * 插入或更新评论草稿
     */
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertOrUpdate(draft: CommentDraft)
    
    /**
     * 删除指定视频的评论草稿
     */
    @Query("DELETE FROM comment_draft WHERE videoId = :videoId")
    fun deleteDraftByVideoId(videoId: Int): Int
    
    /**
     * 删除所有评论草稿
     */
    @Query("DELETE FROM comment_draft")
    fun deleteAllDrafts(): Int
}